package smsManagment;

import java.util.Date;

import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;

public class SmsReceiver {

	private String sms = "";
	private ContentResolver cr;
	private final int smsBody = 11, smsDate = 4;
	private Date now;

	public SmsReceiver(ContentResolver cr) {
		this.cr = cr;
	}

	public void readSms() {
		Uri uriSMSURI = Uri.parse("content://sms/inbox");
		Cursor cur = cr.query(uriSMSURI, null, null, null, null);
		cur.moveToFirst();// Do not forget to read every sms
		if (now.before(new Date(cur.getLong(smsDate)))) {
			// verifie que le sms que l on regarde a bien ete recu
			// ulterieurement a l action run ou a la derniere lecture
			sms += "sms : " + cur.getString(smsBody);
		}

		/* setNow(Calendar.getInstance().getTime()) */
		// On ne reliera pas le dernier sms traite grace a set now

	}

	public String getSms() {
		sms = "";
		readSms();
		return sms;
	}

	public void setNow(Date now) {
		this.now = now;
	}

}
